package com.kws.merchant.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kws.merchant.domain.OnlineInquiryEntity;
import com.kws.merchant.domain.vo.AcceptOfferVo;
import com.kws.merchant.domain.vo.QuotationVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : zhangbenting
 * @date : 2024/11/12 14:10
 * @Version: 1.0
 */
public interface OnlineInquiryMapper extends BaseMapper<OnlineInquiryEntity> {

    @Select("SELECT " +
            " a.id AS scheme_id, " +
            " a.item_name AS scheme_name, " +
            " b.merchant_id, " +
            " b.status, " +
            " c.company_name AS merchant_name, " +
            " d.item_scheme_price AS price  " +
            "FROM " +
            " tb_item AS a " +
            " LEFT JOIN tb_item_scheme_merchant AS b ON a.id = b.item_id " +
            " LEFT JOIN tb_merchant AS c ON b.merchant_id = c.id " +
            " LEFT JOIN tb_item_scheme AS d ON d.item_id = a.id" +
            " WHERE d.id = ${schemeId}")
    List<QuotationVo> getMerchantQuotation(@Param("schemeId") Long schemeId);


    @Select("SELECT " +
            " a.price, " +
            " a.merchant_id, " +
            " b.scheme_name, " +
            " b.scheme_id, " +
            " b.station_id, " +
            " b.station_type, " +
            " c.company_name AS merchant_name  " +
            "FROM " +
            " tb_item_scheme_merchant AS a " +
            " LEFT JOIN tb_item_user_scheme AS b ON a.scheme_id = b.scheme_id " +
            " LEFT JOIN tb_merchant AS c ON a.merchant_id = c.id  " +
            "WHERE " +
            " a.`status` = 0  " +
            " AND a.id = ${quotationId}")
    AcceptOfferVo acceptOffer(@Param("quotationId") Long quotationId);
}
